using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using RAIN.Core;
using RAIN.Action;
using RAIN.Representation;

[RAINAction]
public class RememberObjectPosition : RAINAction
{
	public Expression gameObject = new Expression();
	public Expression memoryVariable = new Expression();

    public RememberObjectPosition()
    {
        actionName = "RememberPlayerPosition";
    }

    public override ActionResult Execute(AI ai)
    {
		if(gameObject != null && gameObject.IsValid && memoryVariable != null && memoryVariable.IsValid && memoryVariable.IsVariable) {
			GameObject obj = gameObject.Evaluate(ai.DeltaTime, ai.WorkingMemory).GetValue<GameObject>();
			if(obj != null) {
				ai.WorkingMemory.SetItem<Vector3>(memoryVariable.VariableName, obj.transform.position);
				Debug.Log(memoryVariable.VariableName+": "+ai.WorkingMemory.GetItem<Vector3>(memoryVariable.VariableName));
				return ActionResult.SUCCESS;
			} else {
				return ActionResult.FAILURE;
			}
		} else {
			Debug.LogError("Expressions not set in custom action: "+GetType().Name);
			return ActionResult.FAILURE;
		}
    }
}